class Shop::SessionsController < ShopController
  skip_before_action :authenticate_shoper!

  def new
    if current_shoper.presence
      redirect_to shop_root_path, notice: "已登录."
    end
  end

  def create
    shoper = Shoper.find_by_phone params[:phone]
    if shoper && shoper.authenticate(params[:password])
      session[:shoper_id] = shoper.id
      redirect_to shop_root_path, notice: "登录成功."
    else
      flash.now.alert = "电话号码或密码错误."
      render :new
    end
  end

  def destroy
    session[:shoper_id] = nil
    redirect_to new_shop_session_path
  end
end
